package com.structure.algorithm;

/**
 * Created by sucre on 2015/10/26.
 */
public class LinkedListOperate {
    //链表反转
    private Node reverse(Node current){
        if (current == null || current.next == null) return current;
        Node nextNode = current.next;
        current.next = null;
        Node reverseRest = reverse(nextNode);
        nextNode.next = current;
        return reverseRest;
    }
    //对两个有序链接进行合并，使得合并后的链接还是有序的
    private Node merge(Node pHead,Node pBehind){
        if(pHead ==null){
            return pBehind;
        }
        if (pBehind ==null){
            return pHead;
        }
        Node pMergeHead = null;
        if(pHead.value < pBehind.value){
            pMergeHead = pHead;
            pMergeHead.next = merge(pHead.next,pBehind);
        }else{
            pMergeHead = pBehind;
            pMergeHead.next = merge(pHead,pBehind.next);
        }
        return pMergeHead;
    }
    public static void main(String args[]){

    }
}
class Node{
    int value;
    Node next;

    public Node(int val) {
        this.value = val;
    }
}